package com.jcz.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.jcz.biz.Vote_OptionBiz;
import com.jcz.biz.Vote_SubjectBiz;
import com.jcz.bizImpl.Vote_OptionBizImpl;
import com.jcz.bizImpl.Vote_SubjectBizImpl;
import com.jcz.entity.Vote_Option;
import com.jcz.entity.Vote_Subject;
import com.opensymphony.xwork2.ActionSupport;

public class SubjectAction extends ActionSupport {

	private Vote_Subject subject;
	private String[] options;
	
	public Vote_Subject getSubject() {
		return subject;
	}
	public void setSubject(Vote_Subject subject) {
		this.subject = subject;
	}
	public String[] getOptions() {
		return options;
	}
	public void setOptions(String[] options) {
		this.options = options;
	}
	
	
	Vote_SubjectBiz sBiz=new Vote_SubjectBizImpl();
	Vote_OptionBiz oBiz=new Vote_OptionBizImpl();
	public String save(){
		
		sBiz.addSubject(subject);
		for (String string : options) {
			Vote_Option option=new Vote_Option();
			option.setVo_option(string);
			option.setVote_Subject(subject);
			oBiz.addOption(option);
		}
		return "save";
	}
	public String list(){
		return "list";
	}
	
	public String read(){
		HttpServletRequest request=ServletActionContext.getRequest();
		String id=request.getParameter("subject.id");
		this.setSubject(sBiz.findById(Integer.parseInt(id)));
		return "read";
	}
	
	public String modify(){
		sBiz.updateSubject(subject);
		for (String string : options) {
			Vote_Option option=new Vote_Option();
			option.setVo_option(string);
			option.setVote_Subject(subject);
			oBiz.updateOption(option);
		}
		return "modify";
	}
}
